package com.xyh.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xyh.system.model.Menu;
import com.xyh.system.model.User;
import com.xyh.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;


@Controller
public class IndexController {

    @Autowired
    private IMenuService menuService;
    @Autowired
    private IUserService userService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private ILoginLogService loginLogService;
    @Autowired
    private ISysLogService sysLogService;

    @GetMapping(value = {"/","/index","/main"})
    public String index(Model model){
        System.out.println("======IndexController.index======");
        List<Menu> menus = menuService.selectCurrentUserMenuTree();
        System.out.println("menus = " + menus);
        model.addAttribute("menus",menus);
        return "index";
    }

    @GetMapping("/welcome")
    public String welcome(Model model){
        int userCount = userService.count(new LambdaQueryWrapper<User>().eq(User :: getDeleted,0));
        model.addAttribute("userCount",userCount);
        int roleCount = roleService.count();
        model.addAttribute("roleCount",roleCount);
        int menuCount = menuService.count();
        model.addAttribute("menuCount",menuCount);
        int loginLogCount = loginLogService.count();
        model.addAttribute("loginLogCount",loginLogCount);
        int sysLogCount = sysLogService.count();
        model.addAttribute("sysLogCount",sysLogCount);
        return "welcome";
    }
}
